home *** CD-ROM | disk | FTP | other *** search
/ DOpus Plus / DOpus Plus.iso / Tutorial / ARexx Tutorial / TuteRexx / DirTree.dopus5 < prev    next >
Text File  |  1998-10-07  |  3KB  |  121 lines

  1. /*
  2. $VER: DirTree.dopus5 0.2 (7.10.98)
  3.  
  4. Call as:  ARexx  DOpus5:ARexx/DirTree.dopus5 [REGEN] <Device>
  5.  
  6.           Flags  Run Async
  7.  
  8.   where:  REGEN  = causes a new directory tree file to be created.
  9.           Device = the device, eg. HD0:, SD0:, DF0:, etc
  10.  
  11. Example:  DirTree.dopus5 HD0:
  12.  
  13. */
  14. options results
  15. parse arg regen device
  16. if device = '' then device = regen
  17. regen = regen ~= device
  18.  
  19. address 'DOPUS.1'
  20. if ~show('l','rexxsupport.library') then
  21.   call addlib('rexxsupport.library',0,-30)
  22.  
  23. device = strip(strip(device,,'"'))
  24. oldcd = pragma('d',device)
  25. device = pragma('d',oldcd)
  26. if right(device,1) ~= ':' then do
  27.   dopus request '"Specify DEVICE only, eg. ''HD0:''" OK'
  28.   exit
  29.   end
  30. tfile = left(device,pos(':',device))||'.dirtree'
  31. if regen then call delete(tfile)
  32.  
  33. if ~exists(tfile) then do
  34.   address command 'List 'device' DIRS ALL LFORMAT "%P%N" >T:dirtree.temp'
  35.   address command 'Sort T:dirtree.temp 'tfile
  36.   'command protect 'tfile' set H'
  37.   call delete('T:dirtree.temp')
  38.   end
  39.  
  40. if ~open('dirtree',tfile,'r') then do
  41.   dopus request '"ERROR: Unable to open ''tree'' file." OK'
  42.   exit
  43.   end
  44. else do
  45.   totlines = 0
  46.   do while ~eof('dirtree')
  47.     call readln('dirtree')
  48.     totlines = totlines + 1
  49.   end
  50.   call seek('dirtree',0,'b')
  51.   nlength = length(totlines)
  52.   end
  53.  
  54. lister new invisible mode name
  55. handle = result
  56. lister set handle field off
  57. lister set handle toolbar
  58. lister set handle busy on
  59. info.NAME = copies('0',nlength)
  60. info.DISPLAY = device
  61. lister addstem handle info.
  62. lister refresh handle full
  63. lister set handle value info.NAME device
  64. lister set handle visible on
  65.  
  66. linenum = 1
  67. do while ~eof('dirtree')
  68.   dirline = readln('dirtree')
  69.   path = dirline
  70.   if pos(':',dirline) ~= 0 then parse var dirline dev ':' dirline
  71.   if dirline ~= '' then do
  72.     linenum = linenum + 1
  73.     if pos('/',dirline) ~= 0 then do
  74.       howmany = 0
  75.       do while pos('/',dirline) ~= 0
  76.         parse var dirline fore'/'dirline
  77.         howmany = howmany + 1
  78.       end
  79.       dirline = copies(' ',3 * howmany)||dirline
  80.       end
  81.     dirline = '   '||dirline
  82.     do i = 1 to length(dirline) by 3
  83.       if substr(dirline,i + 3,1) ~= ' ' | substr(dirline,i + 4,1) ~= ' ' then do
  84.         dirline = overlay('+--',dirline,i)
  85.         leave
  86.         end
  87.     end
  88.     info.NAME = right(linenum,nlength,'0')
  89.     info.DISPLAY = dirline
  90.     lister addstem handle info.
  91.     lister refresh handle
  92.     lister set handle value info.NAME path
  93.     end
  94. end
  95. call close('dirtree')
  96. lister set handle busy off
  97.  
  98. call openport('DirTree-handler')
  99. lister set handle handler 'DirTree-handler'
  100.  
  101. do until event = 'inactive'
  102.   if waitpkt('DirTree-handler') then do
  103.     packet = getpkt('DirTree-handler')
  104.     if packet ~= '00000000'x then do
  105.       event = getarg(packet,0)
  106.       name = getarg(packet,2)
  107.       if event = 'doubleclick' then do
  108.         lister query handle value name
  109.         path = result
  110.         lister set handle handler
  111.         lister set handle toolbar toolbar
  112.         lister wait handle quick
  113.         lister read handle path force
  114.         end
  115.     call reply(packet,0)
  116.     end
  117. end
  118.  
  119. call closeport('DirTree-handler')
  120. exit
  121.